package com.tr.rentcar.controller.goods;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.tr.rentcar.common.BaseServlet;
import com.tr.rentcar.model.bean.CarBrand;
import com.tr.rentcar.model.bean.CarStyle;
import com.tr.rentcar.model.bean.CarUse;
import com.tr.rentcar.model.bean.Cars;
import com.tr.rentcar.model.bean.Discount;
import com.tr.rentcar.model.bean.Place;
import com.tr.rentcar.model.bean.PlaceStore;
import com.tr.rentcar.model.bean.UserAddress;
import com.tr.rentcar.model.dao.CarBrandDao;
import com.tr.rentcar.model.dao.CarInfoDao;
import com.tr.rentcar.model.dao.CarStyleDao;
import com.tr.rentcar.model.dao.CarUseDao;
import com.tr.rentcar.model.dao.DiscountDao;
import com.tr.rentcar.model.dao.PlaceDao;
import com.tr.rentcar.model.dao.UserAddressDao;

/***
 * 商品分类展示
 * @author dell
 *
 */
@WebServlet("/goods")
public class GoodsController extends HttpServlet {
	
	/**
	 * 商城页面初始化
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			CarInfoDao cid=new CarInfoDao();
			List<CarUse> list1=new CarUseDao().getAll();
			req.setAttribute("carUse", list1);
			List<CarStyle> list2=new CarStyleDao().getAll();
			req.setAttribute("carStyle", list2);
			List<CarBrand> list3=new CarBrandDao().getAll();
			req.setAttribute("carBrand", list3);
			//获取活动
			List<Discount> activity = new DiscountDao().findAll();
			req.setAttribute("activity", activity);
			//获取全部车辆
			List<Cars> listAll = cid.getAllLimit();
			req.setAttribute("cars", listAll);
			//获取所在地
			PlaceDao pd=new PlaceDao();
			List<Place> placeList=pd.getAll();
			req.setAttribute("place", placeList);
			//从参数中获取门店所在地的ID
			String qupid=req.getParameter("qulocation");
			String huanpid=req.getParameter("huanlocation");
			List<PlaceStore> quList=null;
			List<PlaceStore> huanList=null;
			if(qupid==null){//如果从页眉菜单直接过来的的
				quList=pd.getAllByid("1");
				huanList=pd.getAllByid("1");
			}else{//如果选择了时间地点过来的
				quList=pd.getAllByid(qupid);
				huanList=pd.getAllByid(huanpid);
			}
			req.setAttribute("qulist", quList);
			req.setAttribute("huanlist", huanList);
			
			//System.out.println("GoodsControllerd的获取记录数："+cid.getAllCount());
			//设置总记录数
			req.setAttribute("totalCount", cid.getAllCount());
			req.getRequestDispatcher("/WEB-INF/jsp/goods.jsp").forward(req, resp);
		} catch (SQLException e) {
			req.getRequestDispatcher("/WEB-INF/jsp/error.jsp").forward(req, resp);
			e.printStackTrace();
			
		}
	}

}
